package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import flashx.textLayout.formats.TextAlign;

	public class MenuContent extends Sprite
	{
		private var ball36Content:Sprite;
		private var resultBallContent:Sprite;
		private var resultScoreContent:Sprite;
		private var menuContentWidth:Number=480;
		private var menuContentHeight:Number=80;
		private var _textFormat:TextFormat;
		private var _resultBall:Array=["1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2"];
		private var _rateBall:Array=["0.1", "0.2", "0.1", "0.2", "0.1", "0.2", "0.1", "0.2", "0.1", "0.2", "0.1", "0.2"];
		private var _scoreResult:Array=["4.6", "2.8", "50.6", "4.6", "2.8", "50.6", "4.6", "2.8", "50.6", "4.6", "2.8", "50.6"];
		private var _ratetextFormat:TextFormat;
		private var _scoretextFormat:TextFormat;

		public function MenuContent(resultBall:Array=null, rateBall:Array=null, scoreResult:Array=null)
		{
			super();
			this._resultBall=resultBall == null ? [] : resultBall;
			this._rateBall=rateBall == null ? [] : rateBall;
			this._scoreResult=scoreResult == null ? [] : scoreResult;
			var bg:Sprite=new Sprite();
			bg.graphics.beginFill(0x323232, 0);
			bg.graphics.drawRect(0, 0, menuContentWidth, menuContentHeight);
			bg.graphics.endFill();
			addChild(bg);
			ball36Content=new Sprite();
			ball36Content.addChild(new Bitmap(new BackGround36Ball as BitmapData));
			ball36Content.x=4;
			ball36Content.y=4;

			addChild(ball36Content);

			resultBallContent=new Sprite();
			resultBallContent.x=4;
			resultBallContent.y=35;
			resultBallContent.addChild(new Bitmap(new history_bg_1 as BitmapData));
			this._textFormat=new TextFormat("宋体", 13, 0x232334, true);
			this._ratetextFormat=new TextFormat("宋体", 10, 0xffffff, true);
			this._scoretextFormat=new TextFormat("宋体", 8, 0xffffff, true);
			this._ratetextFormat.align=TextAlign.CENTER;
			this._scoretextFormat.align=TextAlign.CENTER;
			var startX:Number=10;
			var m:Number;
			//循环遍历小球以及比率数据，显示在正确位置
			for (var i:int=0; i < this._resultBall.length; i++)
			{
				if (j > 12)
					break;
				m=i;
				if (i > 5)
				{
					startX=120
					m=i - 5;
				}
				var _tip1:TextField=new TextField();
				_tip1.filters=[new GlowFilter(0Xffffff,0.3,2,2,255)];
				_tip1.defaultTextFormat=this._textFormat;
				_tip1.autoSize=TextFieldAutoSize.CENTER;
				_tip1.mouseEnabled=false;
				_tip1.text=this._resultBall[i];
				_tip1.x=m * 20 + startX;
				_tip1.y=6;
				resultBallContent.addChild(_tip1);
				var _tipRate:TextField=new TextField();
				_tipRate.filters=[new GlowFilter(0X778899,0.5,2,2,255)];
				_tipRate.defaultTextFormat=this._ratetextFormat;
				_tipRate.autoSize=TextFieldAutoSize.CENTER;
				_tipRate.mouseEnabled=false;
				_tipRate.text=this._rateBall[i];
				_tipRate.x=m * 20 + startX - 4;
				_tipRate.y=22;
				resultBallContent.addChild(_tipRate);
				if (i == 5)
				{
					_tip.x+=2;
					_tipRate.x+=2;
				}

			}
			addChild(resultBallContent);

			resultScoreContent=new Sprite();
			resultScoreContent.x=270;
			resultScoreContent.y=4;
			var score_1:Bitmap=new Bitmap(new score_red as BitmapData);
			var score_2:Bitmap=new Bitmap(new score_even as BitmapData);
			score_2.y=score_1.y + score_1.height + 2;
			var score_3:Bitmap=new Bitmap(new score_1st as BitmapData);
			score_3.y=score_2.y + score_2.height + 2;
			var score_4:Bitmap=new Bitmap(new score_voisin as BitmapData);
			score_4.y=score_3.y + score_3.height + 2;
			resultScoreContent.addChild(score_1);
			resultScoreContent.addChild(score_2);
			resultScoreContent.addChild(score_3);
			resultScoreContent.addChild(score_4);

			//循环遍历分数百分比数据，显示在正确位置
			var lineNum:Number;
			for (var j:int=0; j < this._scoreResult.length; j++)
			{
				if (j > 12)
					break;
				m=j % 3;
				lineNum=Math.floor(j / 3);
				//trace(j/3);
				var _tip:TextField=new TextField();
				_tip.filters=[new GlowFilter(0X778899,0.3,2,2,255)];
				_tip.defaultTextFormat=this._scoretextFormat;
				_tip.autoSize=TextFieldAutoSize.CENTER;
				_tip.mouseEnabled=false;
				_tip.text=this._scoreResult[j];
				_tip.x=60 - _tip.width / 2 + m * 65;
				if (m == 2)
				{
					_tip.x+=3;
				}
				//trace(lineNum);
				_tip.y=8 - _tip.height / 2 + lineNum * 19;
				resultScoreContent.addChild(_tip);
				if (lineNum == 0){
					_tip.y-=2;
				}
				else if (lineNum == 1){
					_tip.y-=2;
				}
				else if (lineNum == 2)
				{
					_tip.y-=3;
				}
				else if (lineNum == 3)
				{
					_tip.y-=4;
				}
			}

			addChild(resultScoreContent);
		}

		public function get scoreResult():Array
		{
			return _scoreResult;
		}

		public function set scoreResult(value:Array):void
		{
			_scoreResult=value;
		}

		public function get rateBall():Array
		{
			return _rateBall;
		}

		public function set rateBall(value:Array):void
		{
			_rateBall=value;
		}

		public function get resultBall():Array
		{
			return _resultBall;
		}

		public function set resultBall(value:Array):void
		{
			_resultBall=value;
		}

		private function drawShape(parentContainer:Sprite, swidth:Number, sheight:Number, sx:Number=0, sy:Number=0):void
		{
			// TODO Auto Generated method stub
			var shape:Shape=new Shape;
			shape.graphics.beginFill(0x344523);
			shape.graphics.drawRect(sx, sy, swidth, sheight);
			shape.graphics.endFill();
			parentContainer.addChild(shape);
		}

		public function dispose():void
		{

			if (this.ball36Content)
			{
				if (this.ball36Content.parent)
				{
					this.ball36Content.parent.removeChild(this.ball36Content);
				}
				this.ball36Content=null;
			}
			return;
		} // end function
	}
}
